<?
/**
 * VoiceOne Settings/Rules/timesegement/edit
 *
 * Frontend to provide access to the rules system in voiceone.
 * @package voiceone
 * @subpackage  settings_rules
 */
  include ("../../../../admin/config/cfg.php");
  global $cwlang, $cwLanguage;
  require_once("$absBasePath/lib/xajax/xajax.inc.php");
  
  //=================== XAJAX ==================
  function delSegment($div_index){
    global $relBasePath,$cwlang;
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    // Build response
    $objResponse->addAssign("date_".$div_index, 'innerHTML', "");
    // Return the xajaxResponse object
    $objResponse->addScript($script);
    return $objResponse->getXML(); 
  }
  function addSegment($row_index){
    global $relBasePath,$cwlang;
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    // Build response
    $script="  dateFromArr[".$row_index."] = new calendar(document.getElementById('segmentFrom_".$row_index."')); ";
    $script.="  dateFromArr[".$row_index."].year_scroll = false; ";
    $script.="  dateFromArr[".$row_index."].time_comp = false; ";
    $script.="  dateToArr[".$row_index."] = new calendar(document.getElementById('segmentTo_".$row_index."')); ";
    $script.="  dateToArr[".$row_index."].year_scroll = false; ";
    $script.="  dateToArr[".$row_index."].time_comp = false; ";
    $script.="  hourFromArr[".$row_index."] = new calendar(document.getElementById('hourFrom_".$row_index."'));  ";
    $script.="  hourFromArr[".$row_index."].year_scroll = false; ";
    $script.="  hourFromArr[".$row_index."].time_comp = true; ";
    $script.="  hourToArr[".$row_index."] = new calendar(document.getElementById('hourTo_".$row_index."')); ";
    $script.="  hourToArr[".$row_index."].year_scroll = false; ";
    $script.="  hourToArr[".$row_index."].time_comp = true; ";
    ob_start(); 
    ?>
    <table cellpadding="0" cellspacing="0" style="width:70%;">
      <tr><td></td><td colspan="3"><hr /></td></tr>
      <tr>
        <td rowspan="2"><a href="#" onclick="xajax_delSegment(<?=$row_index?>); document.getElementById('ts_number').value=(Number(document.getElementById('ts_number').value) - Number(1)); return false;"><img src="<?=$relBasePath?>/public/img/trash.gif" alt="Cancella segment"></a></td>
        <td><h3 style="text-align: center; margin: 0 0 0 0;">DATE</h3></td>
        <td>
          <table cellpadding="0" cellspacing="0">
            <tr>
              <td class="required" style="text-align: right;"><label for="segmentFrom_<?=$row_index?>"><?=T_("From")?>:</label></td>
              <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentFrom_<?=$row_index?>" name="date_from[]" value="" readonly="readonly"/></td>
              <td style="width:1%;"><a href="#" onclick="dateFromArr[<?=$row_index?>].popup();return false;"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a></td>
              <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentFrom_<?=$row_index?>').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a></td>  
            </tr>
          </table>
        </td>
        <td>
          <table cellpadding="0" cellspacing="0">
            <tr>
              <td class="required" style="text-align: right;"><label for="segmentTo_<?=$row_index?>"><?=T_("To")?>:</label></td>
              <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentTo_<?=$row_index?>" name="date_to[]" value="" readonly="readonly"/>
              <td style="width:1%;"><a href="#" onclick="dateToArr[<?=$row_index?>].popup();"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a>
              <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentTo_<?=$row_index?>').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a>              
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td><h3 style="text-align: center; margin: 0 0 0 0;">TIME</h3></td>
        <td>
          <table cellpadding="0" cellspacing="0">
            <tr>
              <td class="required" style="text-align: right;"><label for="hourFrom_<?=$row_index?>"><?=T_("From")?>:</label></td>
              <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourFrom_<?=$row_index?>" name="hour_from[]" value="" readonly="readonly"/></td>
              <td style="width:1%;"><a href="#" onclick="hourFromArr[<?=$row_index?>].popupHour();"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
              <td style="width:1%;"><a href="#" onclick="document.getElementById('hourFrom_<?=$row_index?>').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>  
            </tr>
          </table>
        </td>
        <td>
          <table cellpadding="0" cellspacing="0">
            <tr>
              <td class="required" style="text-align: right;"><label for="hourTo_<?=$row_index?>"><?=T_("To")?>:</label></td>
              <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourTo_<?=$row_index?>" name="hour_to[]" value="" readonly="readonly"/></td>
              <td style="width:1%;"><a href="#" onclick="hourToArr[<?=$row_index?>].popupHour();"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
              <td style="width:1%;"><a href="#" onclick="document.getElementById('hourTo_<?=$row_index?>').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>
            </tr>
          </table>
        </td>
      </tr>
    <table>
    <?
    $newrow=ob_get_contents();
    ob_end_clean();
    // Return the xajaxResponse object
    $objResponse->addCreate('segmentTable', 'div', "date_".$row_index);
    $objResponse->addAssign("date_".$row_index, 'innerHTML', $newrow);
    $objResponse->addScript($script);
    return $objResponse->getXML(); 
  }
  function roll(){
    global $relBasePath,$cwlang;
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    // Build response
    $html=" <img src=\"".$relBasePath."public/img/ico-progress.gif"."\" alt=\"loading\" /><span>".T_("loading")."</span>";
    $objResponse->addAssign("loading","innerHTML",$html);
    // Return the xajaxResponse object
    return $objResponse->getXML(); 
  }
  function processFormData($formData){
    global $asterisk,$cwlang,$relBasePath;
    // Instantiate the xajaxResponse object
    $objResponse = new xajaxResponse();
    // Extract form's params
    $id=$formData["id"];
    $name=$formData["name"];
    $imgErr="<img src=\"".$relBasePath."/public/img/shutdown.png\" alt=\"error\">&nbsp;&nbsp;";
    // Retrieve all timesegment
    $tsArr=$asterisk->getTimeSegment(0);
    if(is_array($tsArr)){
      foreach($tsArr as $ts) {
        if($id!=$ts["id"]) $tsNameArr[]=$ts["name"];
      }
    }
    // Check Name ((not null)&&(unique))
    $nameErr=false;
    if($name=="") { 
      //name cannot be null
      $errOut[]= T_("Name cannot be null");
      $objResponse->addAssign("nameErr","innerHTML",$imgErr);
      $nameErr=true;  
    }else if((is_array($tsNameArr))&&(in_array($name,$tsNameArr))){
      //name must be unique
      $errOut[]= T_("Name already exists. Please change it");
      $objResponse->addAssign("nameErr","innerHTML",$imgErr);
      $nameErr=true;
    }
    if($nameErr===false) $objResponse->addAssign("nameErr","innerHTML","");
    // Process Form
    if(isset($errOut)){
      $error="<div class=\"AlertBad\"><ul>";
      foreach($errOut as $err) $error.="<li>".$err."</li>";
      $error.="</ul></div>";
      $objResponse->addAssign("alert","innerHTML",$error);
      $objResponse->addAssign("loading","innerHTML","");
    }else{
      $objResponse->addAssign("loading","innerHTML",""); 
      $objResponse->addScript(" document.getElementById('mainform').submit(); ");
    }
    // Return the xajaxResponse object
    return $objResponse->getXML();  
  }
  $xajax = new xajax();
  //$xajax->debugOn();
  $xajax->registerFunction("delSegment");
  $xajax->registerFunction("addSegment");
  $xajax->registerFunction("roll");
  $xajax->registerFunction("processFormData");
  $xajax->processRequests();
  
  //================== POST ==================
  if (count($_POST)>0) {
    $id=$_POST["id"];
    $name=$_POST["name"];
    $date_from=implode("|",$_POST["date_from"]);
    $date_to=implode("|",$_POST["date_to"]);
    $hour_from=implode("|",$_POST["hour_from"]);
    $hour_to=implode("|",$_POST["hour_to"]);
    $week_day=@implode("|",$_POST["week_day"]);
    $day=@implode("|",$_POST["day"]);
    $month=@implode("|",$_POST["month"]);
    $entry=Array(
      "id" => $id,
      "name" => $name,
      "date_from" => $date_from,
      "date_to" => $date_to,
      "hour_from" => $hour_from,
      "hour_to" => $hour_to,
      "week_day" => $week_day,
      "day" => $day, 
      "month" => $month 
    );
    //save the group informations
    $ret=$asterisk->putTimeSegment($entry);
    if ($ret>0) {
      $alert="<div class=\"AlertGood\">".T_("The time segment has been saved")."</div>";
      $_GET["id"]=$ret;
    } else $alert="<div class=\"AlertBad\">".T_("The time segment hasn't been saved")."</div>";
    //return to main page
    goToMainPage($alert);
  }
  
  //================ PAGE LOGIC ================
  //initialize arrays
  $date_from=array();
  $date_to=array();
  $hour_from=array();
  $hour_to=array();
  $week_day=array();
  $day=array();
  $month=array();
  //if modify, read the group informations
  if(isset($_GET["id"])) {
    $ret=$asterisk->getTimeSegment($_REQUEST["id"]);
    if ($err=$asterisk->getError()) die("Error: $err");
    $ret=$ret[0];
    $id=$ret["id"];
    $name=$ret["name"];
    $date_from=split("\|",$ret["date_from"]);
    $date_to=split("\|",$ret["date_to"]);
    // FROM hour array
    $hour_from=split("\|",$ret["hour_from"]);
    $hour_fromArr=split(":",$hour_from);
    // TO hour array
    $hour_to=split("\|",$ret["hour_to"]);
    $hour_toArr=split(":",$hour_to);
    // DAYS FILTER
    $week_day=split("\|",$ret["week_day"]);
    $day=split("\|",$ret["day"]);
    $month=split("\|",$ret["month"]);
    // build HTML
    $i=0;
    while($i<count($date_from)){
      ob_start();
      ?>
      <div id="date_<?=$i?>">
        <table cellpadding="0" cellspacing="0" style="width:70%;">
          <? if($i>0){?> <tr><td></td><td colspan="3"><hr /></td></tr> <? } ?>
          <tr>
            <? if($i==0){?> <td rowspan="2">&nbsp;&nbsp;&nbsp;&nbsp;</td> <? } ?>
            <? if($i>0){ ?> <td rowspan="2"><a href="#" onclick="xajax_delSegment(<?=$i?>); document.getElementById('ts_number').value=(Number(document.getElementById('ts_number').value) - Number(1)); return false;"><img src="<?=$relBasePath?>/public/img/trash.gif" alt="Cancella segment"></a></td> <? } ?>
            <td><h3 style="text-align: center; margin: 0 0 0 0;">DATE</h3></td>
            <td>
              <table cellpadding="0" cellspacing="0">
                <tr>
                  <td class="required" style="text-align: right;"><label for="segmentFrom_<?=$i?>"><?=T_("From")?>:</label></td>
                  <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentFrom_<?=$i?>" name="date_from[]" value="<?=$date_from[$i]?>" readonly="readonly"/></td>
                  <td style="width:1%;"><a href="#" onclick="dateFromArr[<?=$i?>].popup();"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a></td>
                  <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentFrom_<?=$i?>').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a></td>
                </tr>
              </table>
            </td>
            <td>
              <table cellpadding="0" cellspacing="0">
                <tr>
                  <td class="required" style="text-align: right;"><label for="segmentTo_<?=$i?>"><?=T_("To")?>:</label></td>
                  <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentTo_<?=$i?>" name="date_to[]" value="<?=$date_to[$i]?>" readonly="readonly"/></td>
                  <td style="width:1%;"><a href="#" onclick="dateToArr[<?=$i?>].popup();"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a></td>
                  <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentTo_<?=$i?>').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>     
            <td><h3 style="text-align: center; margin: 0 0 0 0;">TIME</h3></td>         
            <td>
              <table cellpadding="0" cellspacing="0">
                <tr>
                  <td class="required" style="text-align: right;"><label for="hourFrom_<?=$i?>"><?=T_("From")?>:</label></td>
                  <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourFrom_<?=$i?>" name="hour_from[]" value="<?=$hour_from[$i]?>" readonly="readonly"/></td>
                  <td style="width:1%;"><a href="#"; onclick="hourFromArr[<?=$i?>].popupHour();return false;"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
                  <td style="width:1%;"><a href="#" onclick="document.getElementById('hourFrom_<?=$i?>').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>  
                </tr>
              </table>
            </td>
            <td>
              <table cellpadding="0" cellspacing="0">
                <tr>
                  <td class="required" style="text-align: right;"><label for="hourTo_<?=$i?>"><?=T_("To")?>:</label></td>
                  <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourTo_<?=$i?>" name="hour_to[]" value="<?=$hour_to[$i]?>" readonly="readonly"/></td>
                  <td style="width:1%;"><a href="#"; onclick="hourToArr[<?=$i?>].popupHour();return false;"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
                  <td style="width:1%;"><a href="#" onclick="document.getElementById('hourTo_<?=$i?>').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </div>
      <?
      $ts_html.=ob_get_contents();
      ob_end_clean();
      //calendar script
      $calendarScript.="  dateFromArr[".$i."] = new calendar(document.getElementById('segmentFrom_".$i."'));  ";
      $calendarScript.="  dateFromArr[".$i."].year_scroll = false; ";
      $calendarScript.="  dateFromArr[".$i."].time_comp = false; ";
      $calendarScript.="  dateToArr[".$i."] = new calendar(document.getElementById('segmentTo_".$i."')); ";
      $calendarScript.="  dateToArr[".$i."].year_scroll = false; ";
      $calendarScript.="  dateToArr[".$i."].time_comp = false; ";
      $calendarScript.="  hourFromArr[".$i."] = new calendar(document.getElementById('hourFrom_".$i."'));  ";
      $calendarScript.="  hourFromArr[".$i."].year_scroll = false; ";
      $calendarScript.="  hourFromArr[".$i."].time_comp = true; ";
      $calendarScript.="  hourToArr[".$i."] = new calendar(document.getElementById('hourTo_".$i."')); ";
      $calendarScript.="  hourToArr[".$i."].year_scroll = false; ";
      $calendarScript.="  hourToArr[".$i."].time_comp = true; ";
      //increment counter
      $i++;
    }
    $ts_number=$i;
    $calendarScript.="  var nSegment=".$ts_number."; "; 
  }
  // else write a new time segment
  else{
    ob_start();
    ?>
    <div id="date_0">
      <table cellpadding="0" cellspacing="0" style="width:70%;">
        <tr>
          <td rowspan="2">&nbsp;&nbsp;&nbsp;&nbsp;</td>
          <td><h3 style="text-align: center; margin: 0 0 0 0;">DATE</h3></td>
          <td>
            <table cellpadding="0" cellspacing="0">
              <tr>
                <td class="required" style="text-align: right;"><label for="segmentFrom_0"><?=T_("From")?>:</label></td>
                <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentFrom_0" name="date_from[]" value="<?=$date_from[0]?>" readonly="readonly"/></td>
                <td style="width:1%;"><a href="#" onclick="dateFromArr[0].popup();"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a></td>
                <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentFrom_0').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a></td>
              </tr>
            </table>
          </td>
          <td>
            <table cellpadding="0" cellspacing="0">
              <tr>
                <td class="required" style="text-align: right;"><label for="segmentTo_0"><?=T_("To")?>:</label></td>
                <td style="width:1%;"><input type="text" size="8" maxlength="30" id="segmentTo_0" name="date_to[]" value="<?=$date_to[0]?>" readonly="readonly"/></td>
                <td style="width:1%;"><a href="#" onclick="dateToArr[0].popup();"><img src="<?=$relBasePath?>/public/js/calendar/img/cal.gif" alt="Clicca per selezionare una data"></a></td>
                <td style="width:1%;"><a href="#" onclick="document.getElementById('segmentTo_0').value=''; return false"><img src="<?=$relBasePath?>/public/js/calendar/img/del.gif" alt="Clicca per cancellare la data"></a></td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>     
          <td><h3 style="text-align: center; margin: 0 0 0 0;">TIME</h3></td>         
          <td>
            <table cellpadding="0" cellspacing="0">
              <tr>
                <td class="required" style="text-align: right;"><label for="hourFrom_0"><?=T_("From")?>:</label></td>
                <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourFrom_0" name="hour_from[]" value="<?=$hour_from[0]?>" readonly="readonly"/></td>
                <td style="width:1%;"><a href="#"; onclick="hourFromArr[0].popupHour();return false;"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
                <td style="width:1%;"><a href="#" onclick="document.getElementById('hourFrom_0').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>  
              </tr>
            </table>
          </td>
          <td>
            <table cellpadding="0" cellspacing="0">
              <tr>
                <td class="required" style="text-align: right;"><label for="hourTo_0"><?=T_("To")?>:</label></td>
                <td style="width:1%;"><input type="text" size="8" maxlength="30" id="hourTo_0" name="hour_to[]" value="<?=$hour_to[0]?>" readonly="readonly"/></td>
                <td style="width:1%;"><a href="#"; onclick="hourToArr[0].popupHour();return false;"><img src="<?=$relBasePath?>/public/img/time_add.gif" alt="Clicca per selezionare una data"></a></td>
                <td style="width:1%;"><a href="#" onclick="document.getElementById('hourTo_0').value=''; return false"><img src="<?=$relBasePath?>/public/img/time_delete.gif" alt="Clicca per cancellare la data"></a></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </div>
    <?
    $ts_html=ob_get_contents();
    ob_end_clean();
    //calendar script
    $ts_number=1;
    $calendarScript.="  var nSegment=1; "; 
    $calendarScript.="  dateFromArr[0] = new calendar(document.getElementById('segmentFrom_0'));  ";
    $calendarScript.="  dateFromArr[0].year_scroll = false; ";
    $calendarScript.="  dateFromArr[0].time_comp = false; ";
    $calendarScript.="  dateToArr[0] = new calendar(document.getElementById('segmentTo_0')); ";
    $calendarScript.="  dateToArr[0].year_scroll = false; ";
    $calendarScript.="  dateToArr[0].time_comp = false; ";
    $calendarScript.="  hourFromArr[0] = new calendar(document.getElementById('hourFrom_0'));  ";
    $calendarScript.="  hourFromArr[0].year_scroll = false; ";
    $calendarScript.="  hourFromArr[0].time_comp = true; ";
    $calendarScript.="  hourToArr[0] = new calendar(document.getElementById('hourTo_0')); ";
    $calendarScript.="  hourToArr[0].year_scroll = false; ";
    $calendarScript.="  hourToArr[0].time_comp = true; ";
  }
  //initialize calendar object array
  $initScript="<script language=\"JavaScript\">";
  $initScript.="  var dateFromArr = new Array(); ";
  $initScript.="  var dateToArr = new Array(); ";
  $initScript.="  var hourFromArr = new Array(); ";
  $initScript.="  var hourToArr = new Array(); ";
  $initScript.=$calendarScript;
  $initScript.="</script> ";
  //================ MAIN CONTENTS ================
  ob_start();
  $xajax->printJavascript("../../../../admin/lib/xajax/"); 
  ?>
  <?$sel="timesegment";include("../../navigation.php");?>
  
  <div class="SectionHeader">
    <div id="loading" style="float: right;"></div>
    <h1><?=T_("New/Edit Time Segment")?></h1>
    <h3><a href="../" class="admin" ><?=T_("Return without save")?></a></h3>
  </div>
  <div id="alert"></div>
  <div id="basic_form">
    <form id="mainform" action="<?=$PHP_SELF?><?if (isset($_GET["id"])) echo "?id=".$_GET["id"];?>" method="post" >
      <!-- NAME -->
    	<h2><?=T_("Time segment Definition")?></h2>
      <p class="blockintro"><?=T_("You can choose a time segment that adapt to your needs")?></p>
      <div class="block">
        <dl>
          <dt class="required"><label for="name"><?=T_("Name")?>:</label></dt>
          <dd><input type="text" size="25" maxlength="30" id="name" name="name" value="<?=$name?>" /> <span id="nameErr"></span></dd>
        </dl>
      </div>
      <!-- DATE SEGMENT -->
      <h2><?=T_("Date Segments")?><span class="help"></h2>
      <p class="blockintro"><?=T_("Write the date between which this time segment is available. Leave blank for always.")?></p>
      <div class="block">
        <div id="segmentTable">
          <?=$ts_html?>
        </div>
        <div style="float: right; margin: 0 20px 1em 0;">
          <a class="admin" href="#" onclick="xajax_addSegment(nSegment); nSegment++; document.getElementById('ts_number').value=(Number(document.getElementById('ts_number').value) + Number(1)); return false;">(<?=T_("add Date Segment")?>)</a>
          <input type="hidden" id="ts_number" name="ts_number" value="<?=$ts_number?>" />
        </div>
        <br/>
      </div>
      <!-- DAYS FILTER -->
    	<h2><?=T_("Days Filter")?></h2>
      <p class="blockintro"><?=T_("Select days or months that the Timesegment will match (leave unchecked to select all days)")?></p>
      <div class="block">
        <table>  
          <!-- WEEK DAYS -->
          <tr >
            <td class="required"><label for="week_day[]"><?=T_("Week Days")?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
                <tr>
                  <td><?=T_("Su")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="1" <?if (in_array("1",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("Mo")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="2" <?if (in_array("2",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("Tu")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="3" <?if (in_array("3",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("We")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="4" <?if (in_array("4",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("Th")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="5" <?if (in_array("5",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("Fr")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="6" <?if (in_array("6",$week_day)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("Sa")?> <input type="checkbox" id="week_day[]" name="week_day[]" value="7" <?if (in_array("7",$week_day)) echo "checked=\"checked\""; ?>/></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><hr/></td></tr>
          <!-- MONTH DAYS -->
          <tr>
            <td class="required"><label for="day[]"><?=T_("Month Days")?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
                <tr >
                  <td>1 <input type="checkbox" id="day[]" name="day[]" value="1" <?if (in_array("1",$day)) echo "checked=\"checked\""; ?>/></td> 
                  <td>2 <input type="checkbox" id="day[]" name="day[]" value="2" <?if (in_array("2",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>3 <input type="checkbox" id="day[]" name="day[]" value="3" <?if (in_array("3",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>4 <input type="checkbox" id="day[]" name="day[]" value="4" <?if (in_array("4",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>5 <input type="checkbox" id="day[]" name="day[]" value="5" <?if (in_array("5",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>6 <input type="checkbox" id="day[]" name="day[]" value="6" <?if (in_array("6",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>7 <input type="checkbox" id="day[]" name="day[]" value="7" <?if (in_array("7",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>8 <input type="checkbox" id="day[]" name="day[]" value="8" <?if (in_array("8",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>9 <input type="checkbox" id="day[]" name="day[]" value="9" <?if (in_array("9",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>10 <input type="checkbox" id="day[]" name="day[]" value="10" <?if (in_array("10",$day)) echo "checked=\"checked\""; ?>/></td>
                </tr>
                <tr>
                  <td>11 <input type="checkbox" id="day[]" name="day[]" value="11" <?if (in_array("11",$day)) echo "checked=\"checked\""; ?>/></td> 
                  <td>12 <input type="checkbox" id="day[]" name="day[]" value="12" <?if (in_array("12",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>13 <input type="checkbox" id="day[]" name="day[]" value="13" <?if (in_array("13",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>14 <input type="checkbox" id="day[]" name="day[]" value="14" <?if (in_array("14",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>15 <input type="checkbox" id="day[]" name="day[]" value="15" <?if (in_array("15",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>16 <input type="checkbox" id="day[]" name="day[]" value="16" <?if (in_array("16",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>17 <input type="checkbox" id="day[]" name="day[]" value="17" <?if (in_array("17",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>18 <input type="checkbox" id="day[]" name="day[]" value="18" <?if (in_array("18",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>19 <input type="checkbox" id="day[]" name="day[]" value="19" <?if (in_array("19",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>20 <input type="checkbox" id="day[]" name="day[]" value="20" <?if (in_array("20",$day)) echo "checked=\"checked\""; ?>/></td>
                </tr>
                <tr>
                  <td>21 <input type="checkbox" id="day[]" name="day[]" value="21" <?if (in_array("21",$day)) echo "checked=\"checked\""; ?>/></td> 
                  <td>22 <input type="checkbox" id="day[]" name="day[]" value="22" <?if (in_array("22",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>23 <input type="checkbox" id="day[]" name="day[]" value="23" <?if (in_array("23",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>24 <input type="checkbox" id="day[]" name="day[]" value="24" <?if (in_array("24",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>25 <input type="checkbox" id="day[]" name="day[]" value="25" <?if (in_array("25",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>26 <input type="checkbox" id="day[]" name="day[]" value="26" <?if (in_array("26",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>27 <input type="checkbox" id="day[]" name="day[]" value="27" <?if (in_array("27",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>28 <input type="checkbox" id="day[]" name="day[]" value="28" <?if (in_array("28",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>29 <input type="checkbox" id="day[]" name="day[]" value="29" <?if (in_array("29",$day)) echo "checked=\"checked\""; ?>/></td>
                  <td>30 <input type="checkbox" id="day[]" name="day[]" value="30" <?if (in_array("30",$day)) echo "checked=\"checked\""; ?>/></td>
                </tr>
                <tr>
                  <td>31 <input type="checkbox" id="day[]" name="day[]" value="31" <?if (in_array("31",$day)) echo "checked=\"checked\""; ?>/></td> 
                </tr>
              </table>
            </td>
          </tr>
          <tr><td></td><td class="help" colspan="3"><hr/></td></tr>
          <!-- MONTH -->
          <tr>
            <td class="required"><label for="month[]"><?=T_("Months")?>:</label></td>
            <td colspan="3">
              <table class="timesegment">
                <tr >
                  <td><?=T_("January")?> <input type="checkbox" id="month[]" name="month[]" value="1" <?if (in_array("1",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("February")?> <input type="checkbox" id="month[]" name="month[]" value="2" <?if (in_array("2",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("March")?> <input type="checkbox" id="month[]" name="month[]" value="3" <?if (in_array("3",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("April")?> <input type="checkbox" id="month[]" name="month[]" value="4" <?if (in_array("4",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("May")?> <input type="checkbox" id="month[]" name="month[]" value="5" <?if (in_array("5",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("June")?> <input type="checkbox" id="month[]" name="month[]" value="6" <?if (in_array("6",$month)) echo "checked=\"checked\""; ?>/></td>
                </tr>
                <tr>
                  <td><?=T_("July")?> <input type="checkbox" id="month[]" name="month[]" value="7" <?if (in_array("7",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("August")?> <input type="checkbox" id="month[]" name="month[]" value="8" <?if (in_array("8",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("September")?> <input type="checkbox" id="month[]" name="month[]" value="9" <?if (in_array("9",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("October")?> <input type="checkbox" id="month[]" name="month[]" value="10" <?if (in_array("10",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("November")?> <input type="checkbox" id="month[]" name="month[]" value="11" <?if (in_array("11",$month)) echo "checked=\"checked\""; ?>/></td>
                  <td><?=T_("December")?> <input type="checkbox" id="month[]" name="month[]" value="12" <?if (in_array("12",$month)) echo "checked=\"checked\""; ?>/></td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </div>
      <!-- INPUT BUTTONS -->
      <div class="action">
        <?if (isset($_GET["id"])) {?><input type="hidden" name="id" value="<?=$id?>" /><?}?>
        <a href="#"><img src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Cancel" onclick="location.href='../'; return false;"/></a>
        <a href="#"><img src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" onclick=" document.getElementById('alert').innerHTML=''; xajax_processFormData(xajax.getFormValues('mainform')); "/></a>  
      <!--
        <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-cancel.gif" alt="Cancel" onclick="location.href='../'; return false;"/>
        <input type="image" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" />
      -->
      </div>
    </form>
  </div>
  
  <?=$initScript?>
  
  <?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start(); 
  ?>
        <div class="Sidebar">
          <h1><?=T_("Time Segments")?></h1>
          <p><?=T_("To be done...")?>
        </div>
  <?  
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================

  $smarty->assign("section", "rules");
  $smarty->assign("subsection", "");
  $smarty->assign("templateType", "TwoColLeft");  //OneCol, TwoColLeft, TwoColRight
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('settings.tpl');
?>

